package com.example.lxj.sources.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import com.example.lxj.sources.entity.TbDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.sources.service.ITbDeviceService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 鉴定设备Controller
 *
 * @author lxj
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/sources/device")
public class TbDeviceController extends BaseController {
    @Autowired
    private ITbDeviceService tbDeviceService;

    /**
     * 查询鉴定设备列表
     */
    @Permission(value = "sources:device:list")
    @GetMapping("/list")
    public TableDataInfo list(TbDevice tbDevice, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbDevice> list = tbDeviceService.selectTbDeviceList(tbDevice);
        return getDataTable(list);
    }

    /**
     * 获取鉴定设备详细信息
     */
    @Permission(value = "sources:device:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbDeviceService.selectTbDeviceById(id));
    }

    /**
     * 新增鉴定设备
     */
    @Permission(value = "sources:device:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbDevice tbDevice) {
        return toAjax(tbDeviceService.insertTbDevice(tbDevice));
    }

    /**
     * 修改鉴定设备
     */
    @Permission(value = "sources:device:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbDevice tbDevice) {
        return toAjax(tbDeviceService.updateTbDevice(tbDevice));
    }

    /**
     * 删除鉴定设备
     */
    @Permission(value = "sources:device:remove")
    @DeleteMapping("/{id}")
    public AjaxRes remove(@PathVariable("id") Long id) {
        return toAjax(tbDeviceService.deleteTbDeviceById(id));
    }
}
